<?php //        
//$result = $dbfunc->query("SELECT *,tb_job.* FROM tb_student 
//        LEFT JOIN tb_reg ON tb_student.student_id = tb_reg.student_id 
//        NATURAL JOIN tb_sec NATURAL JOIN tb_subject 
//        NATURAL JOIN tb_job 
//        LEFT JOIN tb_jobsend ON tb_jobsend.job_id = tb_job.sec_id
//        WHERE tb_student.student_id='{$_SESSION['sess_userid']}' AND
//        jobsend_id IS NULL
//        
//        UNION
//        
//        SELECT *,tb_job.* FROM tb_student 
//        LEFT JOIN tb_plan ON tb_student.room_id = tb_plan.room_id
//        NATURAL JOIN tb_sec NATURAL JOIN tb_subject 
//        NATURAL JOIN tb_job 
//        LEFT JOIN tb_jobsend ON tb_jobsend.job_id = tb_job.sec_id
//        WHERE tb_student.student_id='{$_SESSION['sess_userid']}' AND
//        jobsend_id IS NULL
//        "
//        );

$stu_regis = array();

$result = $dbfunc->query("SELECT tb_sec.* FROM tb_student 
        NATURAL JOIN tb_reg 
        NATURAL JOIN tb_sec 
        WHERE tb_student.student_id = '{$_SESSION['sess_userid']}'");
while($item = mysql_fetch_assoc($result)){    
    $stu_regis[$item['sec_id']] = $item;
}

$result = $dbfunc->query("SELECT tb_sec.* FROM tb_student 
        NATURAL JOIN tb_plan 
        NATURAL JOIN tb_sec 
        WHERE tb_student.student_id = '{$_SESSION['sess_userid']}'");
while($item = mysql_fetch_assoc($result)){    
    $stu_regis[$item['sec_id']] = $item;
}

$job_arr = array();
foreach($stu_regis as $key => $value){
    $result = $dbfunc->query("SELECT tb_job.* FROM tb_job 
            LEFT JOIN tb_jobsend ON tb_job.job_id = tb_jobsend.job_id 
            WHERE tb_job.sec_id = '{$value['sec_id']}' AND jobsend_id IS NULL");
    while($item = mysql_fetch_assoc($result)){
        $job_arr[] = $item;
    }
}

//echo "<pre>";
//print_r($job_arr);
//echo "</pre>";
?>

<div align="center">
    <div>เลือกไฟล์เพื่อส่งงาน</div>
    <table border="1">
        <tr>
            <td>ชั้นเรียน</td>
        </tr>
        <?php
        foreach($job_arr as $key => $value){            
            echo "<tr>";
            echo "<td><form action=\"index.php?module=student&page=job_send\" method=\"post\" enctype=\"multipart/form-data\">".$value['job_name']." : <input type=\"hidden\" value=\"{$value['job_id']}\" name=\"job_id\" /><input type=\"file\" name=\"job_file\" /></form></td>";
            echo "</tr>";
        }
        ?>
    </table>
</div>
<script>
    $(":file[name=job_file]").change(function(){
        var form = $(this).parent();
        if(confirm('คุณได้เลือกไฟล์แล้ว แน่ใจว่าต้องการส่ง')){
            form.submit();            
        }
    });
</script>